package org.duoyi.striver.service;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

@Slf4j
public abstract class TaskPost implements InvocationHandler {

    protected String name;

    protected Task target;

    public TaskPost(String name, Task target) {
        this.name = name;
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (!method.getName().equals("start") || method.getParameterTypes().length != 0) {
            return method.invoke(target, args);
        }
        log.info("任务前置开始：【{}】", name);
        doPost();
        log.info("任务前置完成：【{}】", name);
        return method.invoke(target, args);
    }

    public abstract void doPost();
}
